from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-03-06 14:06:53.202139
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 06, Mar, 2021
Time: 14:06:57
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.6133
Nobs: 222.000 HQIC: -47.4358
Log likelihood: 2582.15 FPE: 1.43637e-21
AIC: -47.9927 Det(Omega_mle): 9.66165e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.470238 0.134614 3.493 0.000
L1.Burgenland 0.068159 0.068503 0.995 0.320
L1.Kärnten -0.206303 0.058281 -3.540 0.000
L1.Niederösterreich 0.178440 0.155520 1.147 0.251
L1.Oberösterreich 0.234257 0.139100 1.684 0.092
L1.Salzburg 0.209961 0.073728 2.848 0.004
L1.Steiermark 0.109243 0.099104 1.102 0.270
L1.Tirol 0.124751 0.067004 1.862 0.063
L1.Vorarlberg -0.009463 0.061038 -0.155 0.877
L1.Wien -0.165125 0.129207 -1.278 0.201
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.478998 0.160777 2.979 0.003
L1.Burgenland 0.009607 0.081816 0.117 0.907
L1.Kärnten 0.348521 0.069608 5.007 0.000
L1.Niederösterreich 0.088689 0.185747 0.477 0.633
L1.Oberösterreich -0.111029 0.166135 -0.668 0.504
L1.Salzburg 0.198581 0.088057 2.255 0.024
L1.Steiermark 0.196775 0.118365 1.662 0.096
L1.Tirol 0.143238 0.080026 1.790 0.073
L1.Vorarlberg 0.155790 0.072901 2.137 0.033
L1.Wien -0.495907 0.154319 -3.214 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.309650 0.062391 4.963 0.000
L1.Burgenland 0.093200 0.031750 2.935 0.003
L1.Kärnten -0.020617 0.027012 -0.763 0.445
L1.Niederösterreich 0.077147 0.072081 1.070 0.284
L1.Oberösterreich 0.299820 0.064471 4.650 0.000
L1.Salzburg 0.011163 0.034172 0.327 0.744
L1.Steiermark -0.005310 0.045933 -0.116 0.908
L1.Tirol 0.073143 0.031055 2.355 0.019
L1.Vorarlberg 0.098910 0.028290 3.496 0.000
L1.Wien 0.069781 0.059886 1.165 0.244
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.222429 0.067311 3.304 0.001
L1.Burgenland 0.000291 0.034253 0.008 0.993
L1.Kärnten 0.017846 0.029142 0.612 0.540
L1.Niederösterreich 0.038549 0.077765 0.496 0.620
L1.Oberösterreich 0.388976 0.069554 5.592 0.000
L1.Salzburg 0.086814 0.036866 2.355 0.019
L1.Steiermark 0.173873 0.049555 3.509 0.000
L1.Tirol 0.043891 0.033504 1.310 0.190
L1.Vorarlberg 0.083427 0.030521 2.733 0.006
L1.Wien -0.056614 0.064608 -0.876 0.381
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.514125 0.133619 3.848 0.000
L1.Burgenland 0.066876 0.067996 0.984 0.325
L1.Kärnten 0.010253 0.057850 0.177 0.859
L1.Niederösterreich -0.014826 0.154371 -0.096 0.923
L1.Oberösterreich 0.136186 0.138072 0.986 0.324
L1.Salzburg 0.064297 0.073183 0.879 0.380
L1.Steiermark 0.101427 0.098371 1.031 0.303
L1.Tirol 0.218441 0.066508 3.284 0.001
L1.Vorarlberg 0.026813 0.060587 0.443 0.658
L1.Wien -0.112757 0.128252 -0.879 0.379
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191177 0.097156 1.968 0.049
L1.Burgenland -0.023659 0.049441 -0.479 0.632
L1.Kärnten -0.011837 0.042064 -0.281 0.778
L1.Niederösterreich 0.039019 0.112245 0.348 0.728
L1.Oberösterreich 0.412705 0.100394 4.111 0.000
L1.Salzburg -0.004554 0.053212 -0.086 0.932
L1.Steiermark -0.015834 0.071527 -0.221 0.825
L1.Tirol 0.176626 0.048359 3.652 0.000
L1.Vorarlberg 0.043274 0.044053 0.982 0.326
L1.Wien 0.200170 0.093254 2.147 0.032
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.240249 0.124615 1.928 0.054
L1.Burgenland 0.033789 0.063414 0.533 0.594
L1.Kärnten -0.038305 0.053952 -0.710 0.478
L1.Niederösterreich -0.032645 0.143969 -0.227 0.821
L1.Oberösterreich -0.069977 0.128768 -0.543 0.587
L1.Salzburg 0.069311 0.068251 1.016 0.310
L1.Steiermark 0.394101 0.091743 4.296 0.000
L1.Tirol 0.454791 0.062027 7.332 0.000
L1.Vorarlberg 0.157104 0.056504 2.780 0.005
L1.Wien -0.205310 0.119610 -1.717 0.086
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.127261 0.148616 0.856 0.392
L1.Burgenland 0.023142 0.075628 0.306 0.760
L1.Kärnten -0.069284 0.064343 -1.077 0.282
L1.Niederösterreich 0.194623 0.171698 1.134 0.257
L1.Oberösterreich -0.016978 0.153569 -0.111 0.912
L1.Salzburg 0.253697 0.081397 3.117 0.002
L1.Steiermark 0.141168 0.109413 1.290 0.197
L1.Tirol 0.049124 0.073973 0.664 0.507
L1.Vorarlberg 0.064964 0.067387 0.964 0.335
L1.Wien 0.235493 0.142647 1.651 0.099
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.576895 0.080496 7.167 0.000
L1.Burgenland -0.035581 0.040963 -0.869 0.385
L1.Kärnten -0.014134 0.034851 -0.406 0.685
L1.Niederösterreich 0.008499 0.092997 0.091 0.927
L1.Oberösterreich 0.310125 0.083178 3.728 0.000
L1.Salzburg 0.017580 0.044087 0.399 0.690
L1.Steiermark -0.013639 0.059262 -0.230 0.818
L1.Tirol 0.078686 0.040067 1.964 0.050
L1.Vorarlberg 0.120730 0.036499 3.308 0.001
L1.Wien -0.041871 0.077263 -0.542 0.588
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.128868 0.037247 0.187728 0.238776 0.054783 0.134872 -0.035787 0.169927
Kärnten 0.128868 1.000000 0.004291 0.194475 0.164745 -0.114275 0.146682 0.012303 0.311079
Niederösterreich 0.037247 0.004291 1.000000 0.272833 0.064815 0.249476 0.162211 0.047236 0.335605
Oberösterreich 0.187728 0.194475 0.272833 1.000000 0.296990 0.275021 0.095773 0.074383 0.132933
Salzburg 0.238776 0.164745 0.064815 0.296990 1.000000 0.129719 0.048107 0.086743 -0.003039
Steiermark 0.054783 -0.114275 0.249476 0.275021 0.129719 1.000000 0.119736 0.116638 -0.118028
Tirol 0.134872 0.146682 0.162211 0.095773 0.048107 0.119736 1.000000 0.179468 0.164303
Vorarlberg -0.035787 0.012303 0.047236 0.074383 0.086743 0.116638 0.179468 1.000000 0.027815
Wien 0.169927 0.311079 0.335605 0.132933 -0.003039 -0.118028 0.164303 0.027815 1.000000